package com.cgc.venus.server.app.controller;

import com.cgc.venus.server.app.bean.ConfigMapBean;
import com.cgc.venus.server.app.inter.AppConfigService;
import com.cgc.venus.server.core.bean.response.VenusResponse;
import com.cgc.venus.server.core.bean.response.VenusResponseStatus;
import com.cgc.venus.server.core.exception.VenusException;
import com.cgc.venus.server.core.k8s.inter.K8sConfigMapService;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created by xyr on 2017/9/20.
 * 应用中心-服务配置控制层模块
 */

@Api(value = "应用中心-服务配置",description="服务配置所对应服务的api")
@RequestMapping("/config-admin")
@RestController
public class AppConfigController {


    // 服务层接口


    @Autowired
    private AppConfigService appConfigService;

    /*
    * 超级管理员身份登陆,获得全部空间的配置集
    * 返回的json格式:
    {
        "data": {
            "configMap": [
                {
                    "configMapName": "yk-aly-configmap",
                    "createTime": "2017-09-20 11:22:33",
                    "files": {
                        "items": [
                            {
                                "configMapName": "yk-aly-configmap ",
                                "fileContent": "22222222222222222222",
                                "fileName": "config.txt",
                                "namespace": "default"
                            }
                        ],
                        "total": 100
                    },
                    "namespace": "default"
                }
            ],
            "total": 200
        },
        "meta": {
            "code": 200,
            "message": "success"
        }
    }

    * */
    /*@ApiOperation(value = "获得全部空间的配置集接口", notes = "超级管理员可以获得全部的配置集和文件")
    @RequestMapping(value = "/all/configmap", method = RequestMethod.GET)
    public VenusResponse<Object> getAllConfigMap() throws VenusException {
        // 获得配置集
        List<Map<String,Object>> mapList = k8sConfigMapService.getConfigMap("");
        int mapListSize = mapList.size();

        //int code = VenusResponseStatus.NOT_FOUND;
        //String message = "没有在kubernetes集群中找到配置集";

        Map<String,Object> dataMap = new HashMap<String, Object>();
        *//*if (mapListSize > 0) {
            //code = VenusResponseStatus.OK;
            //message = "success";
            // 重新组装data数据
            dataMap.put("configMap",mapList);
            dataMap.put("total",mapListSize);
        }*//*
        dataMap.put("configMap",mapList);
        dataMap.put("total",mapListSize);
        VenusResponse<Object> response = new VenusResponse<Object>(VenusResponseStatus.OK,"",dataMap);
        return response;
    }*/



    /*
    * 根据用户ID,获得关联空间的配置集
    * */
   /* @ApiOperation(value = "根据选择的空间名称,获得关联空间的配置集接口", notes = "查询关键字 kubernetes 空间名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "namesapce", value = "当前空间", paramType = "string")
    })
    @RequestMapping(value = "/configmap/{namespace}", method = RequestMethod.GET)
    public VenusResponse<Object> getConfigMapByNamespace(@PathVariable("namespace") String namespace) throws VenusException {
        // 获得配置集
        List<Map<String,Object>> mapList = k8sConfigMapService.getConfigMap(namespace);
        int mapListSize = mapList.size();

        int code = VenusResponseStatus.OK;
        String message = "";

        Map<String,Object> dataMap = new HashMap<String, Object>();
        // 重新组装data数据
        dataMap.put("configMap",mapList);
        dataMap.put("total",mapListSize);
        VenusResponse<Object> response = new VenusResponse<Object>(code,message,dataMap);
        return response;
    }*/

    /*
    * 加载选择命名空间选择下拉框
    * */
    /*@ApiOperation(value = "根据用户ID,获得相关联的命名空间接口", notes = "查询关键字 用户ID")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "string")
    })
    @RequestMapping(value = "/namespace/combobox/{userId}", method = RequestMethod.GET)
    public VenusResponse<Object> getNamespaceCombobox(@PathVariable("userId") String userId) throws VenusException  {
        // 非空校验
        if (StringUtils.isBlank(userId))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "用户ID为空");

        int isSuperAdmin = appConfigService.isSuperAdmin(userId);
        List<Map<String,Object>> resultList = new ArrayList<Map<String, Object>>();

        if (isSuperAdmin == 1) {
            // 超级管理员
            resultList = appConfigService.getAllNamespace();
        } else {
            resultList = appConfigService.getAllNamespaceByUser(userId);
        }

        VenusResponse<Object> response = new VenusResponse<Object>(VenusResponseStatus.OK,"",resultList);
        return response;
    }*/

    /*
    * 在指定的命名空间下,添加配置组
    * */
    /*@ApiOperation(value = "新增配置集接口", notes = "关键字段,命名空间,配置集名字")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "namespace", value = "所属命名空间", paramType = "string"),
            @ApiImplicitParam(name = "configMapName", value = "配置集名称", paramType = "string"),
    })
    @RequestMapping(value = "/configmap", method = RequestMethod.POST)
    public VenusResponse<String> addConfigMap(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        String namespace = configMapBean.getNamespace();
        String configMapName = configMapBean.getConfigMapName();
        // 非空判断
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置集名称为空");

        // 704操作异常
        int code = VenusResponseStatus.HANDLE_ERROR;
        String message = namespace + ":空间,新增配置集"+ configMapName + ",失败";

        // 1: 先判断是否存在相同的配置集
        ConfigMap configMap = k8sConfigMapService.queryConfigMap(namespace,configMapName);

        if (configMap != null) {
            // 2: 601 数据重复
            code = VenusResponseStatus.DATA_REPEAT;
            message = namespace + ":空间,已经存在配置集"+ configMapName;
        } else {
            // 新增
            ConfigMap addConfigMap = k8sConfigMapService.addConfigMap(namespace,configMapName);
            if (addConfigMap != null) {
                code = VenusResponseStatus.OK;
                message = namespace + ":空间,新增配置集"+ configMapName + ",成功";
            }
        }

        if (code != VenusResponseStatus.OK) {
            throw new VenusException(code,message);
        }

        VenusResponse<String> response = new VenusResponse<String>(code,message,"");
        return response;
    }*/

    /*
    * 删除配置集
    * */
    /*@ApiOperation(value = "删除配置集接口", notes = "删除字段,命名空间,配置集名字")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "namespace", value = "所属命名空间", paramType = "string"),
            @ApiImplicitParam(name = "configMapName", value = "配置集名称", paramType = "string"),
    })
    @RequestMapping(value = "/configmap", method = RequestMethod.DELETE)
    public VenusResponse<String> deleteConfigMap(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        String namespace = configMapBean.getNamespace();
        String configMapName = configMapBean.getConfigMapName();
        // 非空判断
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置集名称为空");

        // 704 操作失败
        int code = VenusResponseStatus.HANDLE_ERROR;
        String message = "删除空间:" + namespace + ",下的配置集:" + configMapName + ",失败";

        // 删除
        boolean isDelete = k8sConfigMapService.deleteConfigMap(namespace,configMapName);

        if (isDelete) {
            // 删除成功
            code = VenusResponseStatus.OK;
            message = "删除空间:" + namespace + ",下的配置集:" + configMapName + ",成功";
        } else {
            throw new VenusException(code,message);
        }


        VenusResponse<String> response = new VenusResponse<String>(code,message,"");
        return response;

    }*/

    /*
    * 新增配置文件
    * */
    /*@ApiOperation(value = "新增配置文件接口", notes = "新增配置文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "namespace", value = "所属命名空间", paramType = "string"),
            @ApiImplicitParam(name = "configMapName", value = "配置集名称", paramType = "string"),
            @ApiImplicitParam(name = "fileName", value = "配置文件名", paramType = "string"),
            @ApiImplicitParam(name = "fileContent", value = "配置文件内容", paramType = "string")
    })
    @RequestMapping(value = "/configfile", method = RequestMethod.POST)
    public VenusResponse<String> addConfigFile(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        String namespace = configMapBean.getNamespace();
        String configMapName = configMapBean.getConfigMapName();
        String fileName = configMapBean.getFileName();
        String fileContent = configMapBean.getFileContent();
        // 非空判断
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置集名称为空");
        if (StringUtils.isBlank(fileName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件名为空");
        if (StringUtils.isBlank(fileContent))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件内容为空");

        // 704操作异常
        int code = VenusResponseStatus.HANDLE_ERROR;
        String message = "新增配置文件,失败";

        // 1: 先判断是否存在相同的配置文件
        boolean isFileExist = k8sConfigMapService.existConfigFile(namespace,configMapName,fileName);

        if (isFileExist) {
            // 2: 601 数据重复
            code = VenusResponseStatus.DATA_REPEAT;
            message = "配置集:" + configMapName + "中已经存在文件:" + fileName;
        } else {
            // 新增
            ConfigMap addConfigFile = k8sConfigMapService.addConfigFile(namespace,configMapName,fileName,fileContent);
            if (addConfigFile != null) {
                code = VenusResponseStatus.OK;
                message = "配置组："+namespace + "新增配置文件,成功";
            }
        }

        if (code != VenusResponseStatus.OK) {
            throw new VenusException(code,message);
        }

        VenusResponse<String> response = new VenusResponse<String>(code,message,"");
        return response;
    }*/


    /*
    * 修改配置文件
    * */
    /*@ApiOperation(value = "修改配置文件接口", notes = "修改配置文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "namespace", value = "所属命名空间", paramType = "string"),
            @ApiImplicitParam(name = "configMapName", value = "配置集名称", paramType = "string"),
            @ApiImplicitParam(name = "fileName", value = "配置文件名", paramType = "string"),
            @ApiImplicitParam(name = "fileContent", value = "配置文件内容", paramType = "string")
    })
    @RequestMapping(value = "/configfile", method = RequestMethod.PATCH)
    public VenusResponse<String> updateConfigFile(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        String namespace = configMapBean.getNamespace();
        String configMapName = configMapBean.getConfigMapName();
        String fileName = configMapBean.getFileName();
        String fileContent = configMapBean.getFileContent();
        // 非空判断
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置集名称为空");
        if (StringUtils.isBlank(fileName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件名为空");
        if (StringUtils.isBlank(fileContent))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件内容为空");

        // 704操作异常
        int code = VenusResponseStatus.HANDLE_ERROR;
        String message = "修改配置文件,失败";

        // 修改
        ConfigMap configMap = k8sConfigMapService.addConfigFile(namespace,configMapName,fileName,fileContent);

        if (configMap != null) {
            code = VenusResponseStatus.OK;
            message = "修改配置文件,成功";
        } else {
            throw new VenusException(code,message);
        }


        VenusResponse<String> response = new VenusResponse<String>(code,message,"");
        return response;
    }*/

    /*
    * 删除单个配置文件
    * */
    /*@ApiOperation(value = "删除单个配置文件接口", notes = "删除字段,命名空间,配置集名字,文件名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "namespace", value = "所属命名空间", paramType = "string"),
            @ApiImplicitParam(name = "configMapName", value = "配置集名称", paramType = "string"),
            @ApiImplicitParam(name = "fileName", value = "配置文件名称", paramType = "string"),
    })
    @RequestMapping(value = "/configfile", method = RequestMethod.DELETE)
    public VenusResponse<String> deleteConfigFile(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        String namespace = configMapBean.getNamespace();
        String configMapName = configMapBean.getConfigMapName();
        String fileName = configMapBean.getFileName();

        // 非空判断
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置集名称为空");
        if (StringUtils.isBlank(fileName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件名称为空");

        // 704 操作失败
        int code = VenusResponseStatus.HANDLE_ERROR;
        String message = "删除配置文件:" + fileName + ",失败";

        // 删除
        ConfigMap configMap = k8sConfigMapService.deleteConfigFile(namespace,configMapName,fileName);

        if (configMap != null) {
            // 删除成功
            code = VenusResponseStatus.OK;
            message = "删除配置文件:" + fileName + ",成功";
        } else {
            throw new VenusException(code,message);
        }

        VenusResponse<String> response = new VenusResponse<String>(code,message,"");
        return response;

    }*/


    /*
    * 删除单个配置文件
    * */
    /*@ApiOperation(value = "批量删除配置文件接口", notes = "删除字段,命名空间,配置集名字,文件名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "namespace", value = "所属命名空间", paramType = "string"),
            @ApiImplicitParam(name = "configMapName", value = "配置集名称", paramType = "string"),
            @ApiImplicitParam(name = "fileName", value = "配置文件名称", paramType = "string"),
    })
    @RequestMapping(value = "/batch/configfile", method = RequestMethod.DELETE)
    public VenusResponse<String> batchDeleteConfigFile(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        String namespace = configMapBean.getNamespace();
        String configMapName = configMapBean.getConfigMapName();
        String fileName = configMapBean.getFileName();

        // 非空判断
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置集名称为空");
        if (StringUtils.isBlank(fileName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件名称为空");

        // 704 操作失败
        int code = VenusResponseStatus.HANDLE_ERROR;
        String message = "删除配置文件:" + fileName + ",失败";

        // 文件名拆分
        String[] arr = fileName.split(",");
        Map<String,String> map = new HashMap<String, String>();
        for (int i = 0; i < arr.length; i++) {
            map.put(arr[i],"");
        }

        // 删除
        ConfigMap configMap = k8sConfigMapService.batchDeleteConfigFile(namespace,configMapName,map);

        if (configMap != null) {
            // 删除成功
            code = VenusResponseStatus.OK;
            message = "删除配置文件:" + fileName + ",成功";
        } else {
            throw new VenusException(code,message);
        }

        VenusResponse<String> response = new VenusResponse<String>(code,message,"");
        return response;

    }*/

    /*
    * 1: 获取配置组数据,根据空间名称,查询关键字
    * */
    @ApiOperation(value = "获取配置组数据,根据空间名称,查询关键字--接口", notes = "根据空间名称,查询关键字")
    @RequestMapping(value = "/configmap", method = RequestMethod.GET)
    public VenusResponse<List<ConfigMapBean>> getConfigMap(@RequestParam("namespace") String namespace,@RequestParam("queryKey") String queryKey) throws VenusException {
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        List<ConfigMapBean> list = appConfigService.getConfigMap(namespace);
        if (StringUtils.isNotBlank(queryKey)) {
            if (list.size() > 0) {
                list = list.stream().filter(configMapBean -> configMapBean.getConfigMapName().indexOf(queryKey) != -1).collect(Collectors.toList());
            }
        }
        VenusResponse<List<ConfigMapBean>> response = new VenusResponse<List<ConfigMapBean>>(VenusResponseStatus.OK,"",list);
        return response;
    }

    /*
    * 2: 创建新的配置组,根据空间名称,配置组名称
    * */
    @ApiOperation(value = "创建新的配置组,根据空间名称,配置组名称--接口", notes = "根据空间名称,配置组名称")
    @RequestMapping(value = "/configmap", method = RequestMethod.POST)
    public VenusResponse<String> addConfigMap(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        String namespace = configMapBean.getNamespace();
        String configMapName = configMapBean.getConfigMapName();
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置组名称为空");

        boolean flag = appConfigService.addConfigMap(namespace,configMapName);
        String message = "新增配置组:" + configMapName + ",成功";
        if  (!flag) {
            throw new VenusException(VenusResponseStatus.HANDLE_ERROR, "新增配置组:" + configMapName + ",失败");
        }
        VenusResponse<String> response = new VenusResponse<>(VenusResponseStatus.OK,message,"");
        return response;
    }

    /*
    * 3: 删除单个配置组,根据空间名称,配置组名称
    * */
    @ApiOperation(value = "创建新的配置组,根据空间名称,配置组名称--接口", notes = "根据空间名称,配置组名称")
    @RequestMapping(value = "/configmap", method = RequestMethod.DELETE)
    public VenusResponse<String> deleteConfigMap(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        String namespace = configMapBean.getNamespace();
        String configMapName = configMapBean.getConfigMapName();
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置组名称为空");
        boolean flag = appConfigService.deleteConfigMap(namespace,configMapName);
        String message = "删除配置组:" + configMapName + ",成功";
        if (!flag) {
            throw new VenusException(VenusResponseStatus.HANDLE_ERROR,  "删除配置组:" + configMapName + ",失败");
        }
        VenusResponse<String> response = new VenusResponse<>(VenusResponseStatus.OK,message,"");
        return response;
    }

    /*
    * 判断同一空间下是否存在相同的配置组
    * */
    @ApiOperation(value = "判断同一空间下是否存在相同的配置组--接口", notes = "根据空间名称,配置组名称")
    @RequestMapping(value = "/check/configmap", method = RequestMethod.GET)
    public VenusResponse<Integer> validateConfigMap(@RequestParam("namespace") String namespace,@RequestParam("configMapName") String configMapName) throws VenusException {
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置组名称为空");
        boolean flag = appConfigService.validateConfigMap(namespace,configMapName);

        int code = flag ? VenusResponseStatus.DATA_REPEAT : VenusResponseStatus.OK;
        VenusResponse<Integer> response = new VenusResponse<>(VenusResponseStatus.OK,"",code);
        return response;
    }

    /*
    * 判断同一个配置下面是否存在相同名称的配置文件
    * */
    @ApiOperation(value = "判断同一空间下是否存在相同的配置组--接口", notes = "根据空间名称,配置组名称")
    @RequestMapping(value = "/check/configfile", method = RequestMethod.GET)
    public VenusResponse<Integer> validateConfigFile(@RequestParam("namespace") String namespace,
                                                     @RequestParam("configMapName") String configMapName,
                                                     @RequestParam("fileName") String fileName) throws VenusException {
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置组名称为空");
        if (StringUtils.isBlank(fileName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件名称为空");
        boolean flag = appConfigService.validateConfigFile(namespace,configMapName,fileName);
        int code = flag ? VenusResponseStatus.DATA_REPEAT : VenusResponseStatus.OK;
        VenusResponse<Integer> response = new VenusResponse<>(VenusResponseStatus.OK,"",code);
        return response;
    }

    /*
    * 4: 批量删除配置组
    * */

    /*
    * 5: 在配置组下,新增配置文件
    * */
    @ApiOperation(value = "判断同一空间下是否存在相同的配置组--接口", notes = "根据空间名称,配置组名称")
    @RequestMapping(value = "/configfile", method = RequestMethod.POST)
    public VenusResponse<String> addConfigFile(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        String namespace = configMapBean.getNamespace();
        String configMapName = configMapBean.getConfigMapName();
        String fileName = configMapBean.getFileName();
        String fileContent = configMapBean.getFileContent();
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置组名称为空");
        if (StringUtils.isBlank(fileName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件名称为空");
        if (StringUtils.isBlank(fileContent))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件内容为空");
        boolean flag = appConfigService.addConfigFile(namespace,configMapName,fileName,fileContent);
        String message = "新增配置文件:" + configMapBean.getFileName() + ",成功";
        if (!flag) {
            throw new VenusException(VenusResponseStatus.HANDLE_ERROR, "新增配置文件:" + configMapBean.getFileName() + ",失败");
        }
        VenusResponse<String> response = new VenusResponse<>(VenusResponseStatus.OK,message,"");
        return response;
    }

    /*
    * 6: 获取配置文件列表,根据空间名称,配置组名称
    * */
    @ApiOperation(value = "判断同一空间下是否存在相同的配置组--接口", notes = "根据空间名称,配置组名称")
    @RequestMapping(value = "/configfile/{namespace}/{configMapName}", method = RequestMethod.GET)
    public VenusResponse<List<ConfigMapBean>> getConfigFile(@PathVariable("namespace") String namespace,@PathVariable("configMapName") String configMapName) throws VenusException {
        if (StringUtils.isBlank(namespace))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapName))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置组名称为空");
        List<ConfigMapBean> list = appConfigService.getConfigFile(namespace,configMapName);
        VenusResponse<List<ConfigMapBean>> response = new VenusResponse<List<ConfigMapBean>>(VenusResponseStatus.OK,"",list);
        return response;
    }

    /*
    * 7: 修改配置文件内容
    * */
    @ApiOperation(value = "修改配置文件内容--接口", notes = "根据空间名称,配置组名称,配置文件,配置文件内容")
    @RequestMapping(value = "/configfile", method = RequestMethod.PATCH)
    public VenusResponse<String> editConfigFile(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        if (StringUtils.isBlank(configMapBean.getNamespace()))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapBean.getConfigMapName()))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置组名称为空");
        if (StringUtils.isBlank(configMapBean.getFileName()))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件名称为空");
        if (StringUtils.isBlank(configMapBean.getFileContent()))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件内容为空");
        boolean flag = appConfigService.addConfigFile(configMapBean.getNamespace(),configMapBean.getConfigMapName(),configMapBean.getFileName(),configMapBean.getFileContent());
        String message = "修改配置文件:" + configMapBean.getFileName() + ",成功";
        if (!flag) {
            throw new VenusException(VenusResponseStatus.HANDLE_ERROR, "修改配置文件:" + configMapBean.getFileName() + ",失败");
        }
        VenusResponse<String> response = new VenusResponse<>(VenusResponseStatus.OK,message,"");
        return response;
    }

    /*
    * 8: 删除单个配置文件
    * */
    @ApiOperation(value = "判断同一空间下是否存在相同的配置组--接口", notes = "根据空间名称,配置组名称")
    @RequestMapping(value = "/configfile", method = RequestMethod.DELETE)
    public VenusResponse<String> deleteConfigFile(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        if (StringUtils.isBlank(configMapBean.getNamespace()))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapBean.getConfigMapName()))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置组名称为空");
        if (StringUtils.isBlank(configMapBean.getFileName()))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置文件名称为空");
        boolean flag = appConfigService.deleteConfigFile(configMapBean.getNamespace(),configMapBean.getConfigMapName(),configMapBean.getFileName());
        String message = "删除配置文件:" + configMapBean.getFileName() + ",成功";
        if (!flag) {
            throw new VenusException(VenusResponseStatus.HANDLE_ERROR, "删除配置文件:" + configMapBean.getFileName() + ",失败");
        }
        VenusResponse<String> response = new VenusResponse<>(VenusResponseStatus.OK,message,"");
        return response;
    }

    /*
    * 批量删除,配置组
    * */
    @ApiOperation(value = "批量删除,配置组--接口", notes = "根据空间名称,配置组名称列表")
    @RequestMapping(value = "/batch/configmap", method = RequestMethod.DELETE)
    public VenusResponse<String> batchDeleteConfigMap(@RequestBody ConfigMapBean configMapBean) throws VenusException {
        if (StringUtils.isBlank(configMapBean.getNamespace()))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "所属命名空间为空");
        if (StringUtils.isBlank(configMapBean.getConfigMapName()))
            throw new VenusException(VenusResponseStatus.NO_CONTENT, "配置组名称为空");
        // 分割
        String[] configMapArr = configMapBean.getConfigMapName().split(",");
        int arrLen = configMapArr.length;
        int count = 0;
        for (int i = 0; i < arrLen; i++) {
            boolean flag = appConfigService.deleteConfigMap(configMapBean.getNamespace(),configMapArr[i].trim());
            if (flag) {
                count++;
            }
        }
        String message = "本次删除了: " + count + " 个配置组";
        VenusResponse<String> response = new VenusResponse<>(VenusResponseStatus.OK,message,"");
        return response;
    }





}
